/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.controller.PengendaliPenerimaSuratDokument;
import com.controller.PengendaliPeriksaSuratDokument;
import com.util.FormUtil;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import model.Dokument;

/**
 *
 * @author priska
 */
public class FormDokument extends JDialog {

    private JLabel NomorDokument, Perihal, AsalDokument, Penerima, Letak, NamaPetugas, TanggalTerima;
    private JTextField JNomorDokument, JAsalDokument, JPenerima, JLetak, JNamaPetugas, JTanggalTerima;
    private JRadioButton PerihalDokument;
    private JButton Simpan;

    public FormDokument() {
        this.setSize(500, 300);
        FormUtil.centerWindow(this);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setTitle(" Form  Dokument");

        NomorDokument = new JLabel(" Nomor Dokumen ");
        NomorDokument.setBounds(10, 10, 100, 20);
        this.add(NomorDokument);

        Perihal = new JLabel(" Perihal ");
        Perihal.setBounds(10, 40, 100, 20);
        this.add(Perihal);

        AsalDokument = new JLabel(" Asal Dokumen ");
        AsalDokument.setBounds(10, 70, 100, 20);
        this.add(AsalDokument);

        Penerima = new JLabel(" Penerima ");
        Penerima.setBounds(10, 100, 100, 20);
        this.add(Penerima);

        Letak = new JLabel(" Letak ");
        Letak.setBounds(10, 130, 100, 20);
        this.add(Letak);

        NamaPetugas = new JLabel(" Nama Petugas ");
        NamaPetugas.setBounds(10, 160, 100, 20);
        this.add(NamaPetugas);

        TanggalTerima = new JLabel(" Tanggal Terima ");
        TanggalTerima.setBounds(10, 190, 100, 20);
        this.add(TanggalTerima);

        JNomorDokument = new JTextField();
        JNomorDokument.setBounds(120, 10, 100, 20);
        this.add(JNomorDokument);

        ButtonGroup group = new ButtonGroup();
        final JRadioButton tk = new JRadioButton(" Tugas Kuliah");
        tk.setSize(150, 20);
        tk.setLocation(250, 40);
        tk.setVisible(true);
        final JRadioButton p = new JRadioButton(" Panduan ");
        p.setSize(100, 20);
        p.setLocation(120, 40);
        p.setVisible(true);
        group.add(tk);
        group.add(p);
        tk.setEnabled(true);
        p.setEnabled(true);
        this.add(tk);
        this.add(p);

        JAsalDokument = new JTextField();
        JAsalDokument.setBounds(120, 70, 100, 20);
        this.add(JAsalDokument);

        JPenerima = new JTextField();
        JPenerima.setBounds(120, 100, 100, 20);
        this.add(JPenerima);

        JLetak = new JTextField();
        JLetak.setBounds(120, 130, 100, 20);
        this.add(JLetak);

        JNamaPetugas = new JTextField();
        JNamaPetugas.setBounds(120, 160, 100, 20);
        this.add(JNamaPetugas);

        JTanggalTerima = new JTextField("DD-MM-YYYY");
        JTanggalTerima.setBounds(120, 190, 100, 20);
        this.add(JTanggalTerima);

        Simpan = new JButton(" SIMPAN ");
        Simpan.setBounds(100, 220, 100, 30);
        this.add(Simpan);
        Simpan.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String dk = JNomorDokument.getText();
                String a = JPenerima.getText();
                String b = JAsalDokument.getText();
                String c = JLetak.getText();
                String d = JNamaPetugas.getText();
                String gg = JTanggalTerima.getText();
                Dokument ff = new Dokument();
                ff.setAsalDokument(b);
                ff.setLetakDokument(c);
                ff.setNoDokument(dk);
                ff.setPenerimaDokument(a);
                ff.setPetugasPenerimaDokument(d);
                ff.setTanggal(gg);
                if (tk.isSelected()) {
                    ff.setPerihal("Tugas Kuliah");
                } else if (p.isSelected()) {
                    ff.setPerihal("Panduan");
                }
                PengendaliPenerimaSuratDokument.tambahDokument(ff);
                try {
                    PengendaliPenerimaSuratDokument.tambahtableDokument(ff);
                } catch (SQLException ex) {
                    Logger.getLogger(FormDokument.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    PengendaliPenerimaSuratDokument.simpanTabelDokument();
                } catch (SQLException ex) {
                    Logger.getLogger(FormDokument.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (e.getSource() == Simpan) {
                    dispose();
                }
                JOptionPane.showMessageDialog(null, "Document Tersimpan ");
            }
        });
    }
}
